import * as T from '@/api/assetManagement';
import { ref } from 'vue';

export const handlerData = ref<T.TResourceItem>(T.DefaultTResourceItem());
export const Rules = {
  name: [
    { required: true, message: '请输入资源名称', trigger: 'blur' },
    { max: 50, message: '长度在 50 个字符以内', trigger: 'blur' }
  ],
  code: [
    { required: true, message: '请输入资源编号', trigger: 'blur' },
    { max: 50, message: '长度在 50 个字符以内', trigger: 'blur' }
  ],
  from: [
    { required: true, message: '请选择数据来源', trigger: 'blur' },
    { max: 50, message: '长度在 50 个字符以内', trigger: 'blur' }
  ],
 
  data_update_time: [
    { required: true, message: '请选择数据更新时间', trigger: 'change' }
  ],
  owner_org_code: [
    { required: true, message: '请选择资源所属单位', trigger: 'change' }
  ],

  production_resource: [
    { 
      required: true,
      validator: (value, cb) => {
        if(handlerData.value?.is_root != 1) return cb()
        // 验证必填
        // 验证 长度在 50 个字符以内
        if (!value) {
          return cb('请输入生产资源')
        }
        if (value.length > 50) {
          return cb('长度在 50 个字符以内')
        }
        cb()
      },
      trigger: 'change'
    },
    // { required: true, message: '请输入生产资源', trigger: 'blur' },
    // { max: 50, message: '长度在 50 个字符以内', trigger: 'blur' }
  ],

  // 是否是根资源
  is_root: [
    { required: true, message: '请选择是否是根资源', trigger: 'change' }
  ],
}

export function CreateColumnData() {
  return {
    id: '',
    relation: '',
  }
}
export const Columns = [
  {
    title: '序号', dataIndex: 'index', slotName: 'index', width: 80
  },
  
  {
    title: '关系', dataIndex: 'relation', slotName: 'relation'
  },

  {
    title: '资源', dataIndex: 'id', slotName: 'id'
  },
  

  {
    title: '操作', dataIndex: 'operator', slotName: 'operator', width: 120
  },
]